/*
 * I2C_HAL.h
 *
 *  Created on: 08.08.2011
 *      Author: margel
 */

#ifndef I2C_HAL_H_
#define I2C_HAL_H_

#define SDA_LOW() 		GPIO_ResetBits( SHT21_GPIO_PORT, SHT21_GPIO_SDA_PIN )
#define SDA_HIGH()		GPIO_SetBits( SHT21_GPIO_PORT, SHT21_GPIO_SDA_PIN )

#define SCL_LOW()			GPIO_ResetBits( SHT21_GPIO_PORT, SHT21_GPIO_SCL_PIN )
#define SCL_HIGH() 		GPIO_SetBits( SHT21_GPIO_PORT, SHT21_GPIO_SCL_PIN )


// Error codes
typedef enum{
  ACK_ERROR                = 0x01,
  TIME_OUT_ERROR           = 0x02,
  CHECKSUM_ERROR           = 0x04,
  UNIT_ERROR               = 0x08
}etError;

// I2C acknowledge
typedef enum{
  ACK                      = 0,
  NO_ACK                   = 1,
}etI2cAck;

//==============================================================================
void I2c_Init ();
//==============================================================================
//Initializes the ports for I2C interface

//==============================================================================
void I2c_StartCondition ();
//==============================================================================
// writes a start condition on I2C-bus
// input : -
// output: -
// return: -
// note  : timing (delay) may have to be changed for different microcontroller
//       _____
// SDA:       |_____
//       _______
// SCL :        |___

//==============================================================================
void I2c_StopCondition ();
//==============================================================================
// writes a stop condition on I2C-bus
// input : -
// output: -
// return: -
// note  : timing (delay) may have to be changed for different microcontroller
//              _____
// SDA:   _____|
//            _______
// SCL :  ___|

//===========================================================================
uint8_t I2c_WriteByte (uint8_t txByte);
//===========================================================================
// writes a byte to I2C-bus and checks acknowledge
// input:  txByte  transmit byte
// output: -
// return: error
// note: timing (delay) may have to be changed for different microcontroller

//===========================================================================
uint8_t I2c_ReadByte (etI2cAck ack);
//===========================================================================
// reads a byte on I2C-bus
// input:  rxByte  receive byte
// output: rxByte
// note: timing (delay) may have to be changed for different microcontroller

void DelayMicroSeconds( int ms );

#endif /* I2C_HAL_H_ */
